// Test 3

export const animate = (ele, target, spd) => {
  // let start = Date.now(); // remember start time
  // let timer = setInterval(function() {
  //   let timePassed = Date.now() - start;
  //   let step = Math.ceil(Math.abs(timePassed - 5000) / 10);
  //   console.log(step);
  //   if (timePassed >= 5000) {
  //     clearInterval(timer); // finish the animation after 2 seconds
  //     return;
  //   }
  //   ele.style.left = ele.offsetLeft + step + "px";
  // }, speed);
  var lucheng=0;
  var i=0;
  var timer = setInterval(function() {
    var step = [150,100,70,50,30];
    lucheng=lucheng+step[i];
    i++;
    //对步长进行二次加工(大于0向上取整,小于0向下取整)
    // step = step > 0 ? Math.ceil(step) : Math.floor(step);
    //动画原理： 目标位置 = 当前位置 + 步长
    ele.style.left = lucheng+ "px";
    console.log(ele.style.left)
    //检测缓动动画有没有停止
    if (parseInt(ele.style.left)>=400) {
      //处理小数赋值
      // ele.style.left = target + "px";
      var b=new Date();
      var ti=b.toLocaleTimeString()
      console.log("结束",ti)
      clearInterval(timer);
    }
  }, spd);
};
